<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
          <a-row :gutter="32">
            <a-col :span="4">
              <a-form-item label="客户姓名">
                <a-input
                  v-model="queryParam.customerName"
                  placeholder="请输入客户姓名"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="联系电话">
                <a-input
                  v-model="queryParam.phone"
                  placeholder="请输入联系电话"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="服务机构">
                <a-select
                  placeholder="请选择服务机构"
                  v-model="queryParam.orgType"
                  :getPopupContainer="
                    (triggerNode) => {
                      return triggerNode.parentNode || document.body;
                    }
                  "
                  style="width: 100%"
                  allow-clear
                  @change="handleGetProductInfo"
                >
                  <a-select-option
                    v-for="(d, index) in orgTypeOptions"
                    :key="index"
                    :value="d.dictValue"
                    >{{ d.dictLabel }}</a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="进件时间">
                <a-range-picker
                  v-model="dateRange"
                  valueFormat="YYYY-MM-DD"
                  :show-today="true"
                />
              </a-form-item>
            </a-col>

            <a-col>
              <span
                class="table-page-search-submitButtons"
                style="float: right"
              >
                <a-button type="primary" @click="handleQuery"
                  ><a-icon type="search" />查询</a-button
                >
                <a-button style="margin-left: 8px" @click="resetQuery"
                  ><a-icon type="redo" />刷新</a-button
                >
                <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? "收起" : "展开" }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a> -->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false" class="table-card">
      <!-- 增加 -->
      <biz-jinjian-info-add-yushen-form
        v-if="showAddModal"
        ref="bizJinjianInfoAddForm"
        :jinjianTypeOptions="jinjianTypeOptions"
        :backTypeOptions="backTypeOptions"
        :orgTypeOptions="orgTypeOptions"
        @ok="getList"
        @close="showAddModal = false"
      />
      <!-- 编辑 -->
      <biz-jinjian-info-edit-form
        v-if="showEditModal"
        ref="bizJinjianInfoEditForm"
        :jinjianTypeOptions="jinjianTypeOptions"
        :backTypeOptions="backTypeOptions"
        :orgTypeOptions="orgTypeOptions"
        @ok="getList"
        @close="showEditModal = false"
      />
      <!-- 只读 -->
      <biz-jinjian-info-my-qianyue-read-only-form
        v-if="showReadOnlyModal"
        ref="bizJinjianInfoMyQianyuueReadOnlyForm"
        :jinjianTypeOptions="jinjianTypeOptions"
        :backTypeOptions="backTypeOptions"
        :orgTypeOptions="orgTypeOptions"
        @ok="getList"
        @close="showReadOnlyModal = false"
      />

      <!-- 请款 -->
      <biz-jinjian-info-qk-form
        v-if="showQkModal"
        ref="bizJinjianInfoQkForm"
        :jinjianTypeOptions="jinjianTypeOptions"
        :backTypeOptions="backTypeOptions"
        :orgTypeOptions="orgTypeOptions"
        @ok="getList"
        @close="showQkModal = false"
      />
      <!-- 放款 -->
      <biz-jinjian-info-fk-form
        v-if="showFkModal"
        ref="bizJinjianInfoFkForm"
        :jinjianTypeOptions="jinjianTypeOptions"
        :backTypeOptions="backTypeOptions"
        :orgTypeOptions="orgTypeOptions"
        @ok="getList"
        @close="showFkModal = false"
      />

      <!-- 回款 -->
      <biz-jinjian-info-hk-form
        v-if="showHkModal"
        ref="bizJinjianInfoHkForm"
        :jinjianTypeOptions="jinjianTypeOptions"
        :backTypeOptions="backTypeOptions"
        :orgTypeOptions="orgTypeOptions"
        @ok="getList"
        @close="showHkModal = false"
      />

      <advance-table
        title="我的进件信息"
        :pagination="{
          current: queryParam.pageNum,
          pageSize: queryParam.pageSize,
          total: total,
          showSizeChanger: true,
          showLessItems: true,
          showQuickJumper: true,
          showTotal: (total, range) =>
            `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
          onChange: changeSize,
          onShowSizeChange: onShowSizeChange,
        }"
        tableKey="base-bizJinjianInfo-jinjianmy-table"
        rowKey="id"
        size="middle"
        @refresh="getList"
        :columns="columns"
        :data-source="bizJinjianInfoList"
        :loading="loading"
        :format-conditions="true"
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        :scroll="{ x: '100%' }"
      >
        <div class="table-operations" slot="button">
          <!-- <a-button
            type="primary"
            @click="handleAdd"
            v-hasPermi="['biz:bizJinjianInfo:add']"
          >
            <a-icon type="plus" />新增
          </a-button> -->
          <a-button
            type=""
            @click="handleExport"
            v-hasPermi="['biz:bizJinjianInfo:export']"
          >
            <a-icon type="download" />导出
          </a-button>
          <!-- <a-button
            type="danger"
            v-if="!multiple"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['biz:bizJinjianInfo:remove']"
          >
            <a-icon type="delete" />删除
          </a-button> -->
        </div>

        <span slot="jinjianType" slot-scope="{ record }">
          {{ jinjianTypeFormat(record) }}
        </span>

        <span slot="backType" slot-scope="{ record }">
          {{ backTypeFormat(record) }}
        </span>
        <span slot="orgType" slot-scope="{ record }">
          <span v-if="record.orgType && record.isTgOne === '1'">
            {{ orgTypeFormat(record.orgType) }}

            <span v-if="record.productName">
              ({{ record.productName }})</span
            ></span
          >

          <span v-if="record.orgTypeTwo && record.isTgTwo === '1'">
            {{ orgTypeFormat(record.orgTypeTwo) }}
            <span v-if="record.productNameTwo">
              ({{ record.productNameTwo }})</span
            ></span
          >

          <span v-if="record.orgTypeThree && record.isTgThree === '1'">
            {{ orgTypeFormat(record.orgTypeThree)
            }}<span v-if="record.productNameThree">
              ({{ record.productNameThree }})</span
            ></span
          >
        </span>

        <span slot="operation" slot-scope="{ text, record }">
          <a-button type="link" icon="eye" @click="handleRead(record)">
            查看
          </a-button>

          <!-- <a-button
            type="link"
            icon="file-done"
            @click="handleUpdateQianYue(record)"
            v-if="record.jinjianStatus == '4'"
            style="color: orange"
          >
            签约
          </a-button> -->

          <!-- <a-button
            type="link"
            icon="file-done"
            @click="handleUpdateQingKuan(record)"
            v-if="record.jinjianStatus == '5'"
            style="color: blue"
          >
            请款
          </a-button>
          <a-button
            type="link"
            icon="transaction"
            @click="handleUpdateFangK(record)"
            v-if="record.jinjianStatus === '6'"
          >
            放款
          </a-button>

          <a-button
            type="link"
            icon="money-collect"
            @click="handleUpdateHuiK(record)"
            v-if="
              record.fkTime && !record.hkTime && record.jinjianStatus === '8'
            "
            style="color: #ee7600"
          >
            回款
          </a-button>

          <a-button
            type="link"
            icon="check-circle"
            v-if="record.hkTime && record.jinjianStatus === '8'"
            style="color: green"
            disabled
          >
            完成
          </a-button> -->
        </span>
        <span slot="rowindex" slot-scope="{ index }">
          {{ index + 1 }}
        </span>
        <span slot="yxEdu" slot-scope="{ text }">
          ¥ {{ parseFloat(text).toFixed(2) }}
        </span>
        <span slot="sjEdu" slot-scope="{ text }">
          ¥ {{ parseFloat(text ? text : 0).toFixed(2) }}
        </span>
        <span slot="serviceAmount" slot-scope="{ text }">
          ¥ {{ parseFloat(text ? text : 0).toFixed(2) }}
        </span>
        <span slot="id" slot-scope="{ text }">
          <a>
            {{ text }}
          </a>
        </span>
        <span slot="jinjianStatus" slot-scope="{ record }">
          {{ jinjianStatusFormat(record) }}
        </span>
        <span slot="isGps" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>

        <span slot="beiyongKey" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>
        <span slot="hetongQianshu" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>
        <span slot="serviceContractSign" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>
        <span slot="diyaSign" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>
        <span slot="diyaSendOut" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>
        <span slot="carInsurancePolicy" slot-scope="{ text }">
          <a-tag v-if="text == 1" color="green">是</a-tag>
          <a-tag v-else>否</a-tag>
        </span>
        <span slot="phone" slot-scope="{ text }">
          {{ "*******" + text.substring(7, 11) }}
          <!-- {{ text }} -->
        </span>
      </advance-table>
    </a-card>
  </div>
</template>
<script>
import {
  listBizMyListQianyue,
  delBizJinjianInfo,
  exportBizJinjianInfo,
} from "@/api/biz/bizJinjianInfo";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
import BizJinjianInfoAddYushenForm from "@/views/biz/jinjianinfo/modules/BizJinjianInfoAddYushenForm";
import BizJinjianInfoEditForm from "@/views/biz/jinjianinfo/modules/BizJinjianInfoEditQianyueForm";
import { listBizProductInfo } from "@/api/biz/bizProductInfo";
import BizJinjianInfoFkForm from "@/views/biz/jinjianinfo/modules/BizJinjianInfoEditFangKuanForm";
import BizJinjianInfoHkForm from "@/views/biz/jinjianinfo/modules/BizJinjianInfoEditHuiKuanForm";
import BizJinjianInfoQkForm from "@/views/biz/jinjianinfo/modules/BizJinjianInfoEditQingKuanForm";
import BizJinjianInfoMyQianyueReadOnlyForm from "@/views/biz/jinjianinfo/modules/BizJinjianInfoMyQianyueReadOnlyForm";
export default {
  name: "BizJinjianInfo",
  components: {
    AdvanceTable,
    BizJinjianInfoAddYushenForm,
    BizJinjianInfoEditForm,
    BizJinjianInfoFkForm,
    BizJinjianInfoHkForm,
    BizJinjianInfoQkForm,
    BizJinjianInfoMyQianyueReadOnlyForm,
  },
  data() {
    return {
      jinjianStatusOptions: [],
      showReadOnlyModal: false,
      showQkModal: false,
      showHkModal: false,
      showFkModal: false,
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 时间
      dateRange: [],
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 客户进件表格数据
      bizJinjianInfoList: [],
      // 进件类型字典
      jinjianTypeOptions: [],
      // 还款方式字典
      backTypeOptions: [],
      // 机构
      orgTypeOptions: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        status: "1",
        // jinjianStatusArray: ["4", "5", "6", "8"], // 进件状态  4-待签约 5-待请款 6-待放款 8-已放款（成交）
      },
      // 选择的客户信息
      customerInfo: {},
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "50px",
          fixed: "left",
          scopedSlots: { customRender: "rowindex" },
        },
        {
          title: "进件号",
          dataIndex: "id",
          align: "left",
          width: "180px",
          ellipsis: true,
          fixed: "left",
          scopedSlots: { customRender: "id" },
        },

        {
          title: "客户姓名",
          dataIndex: "customerName",
          ellipsis: true,
          align: "center",
          width: "120px",
          fixed: "left",
        },

        {
          title: "签约金额",
          dataIndex: "sjEdu",
          align: "right",
          width: "120px",
          scopedSlots: { customRender: "sjEdu" },
        },
        {
          title: "联系电话",
          dataIndex: "phone",
          ellipsis: true,
          align: "left",
          width: "120px",
          scopedSlots: { customRender: "phone" },
        },
        {
          title: "客户经理",
          dataIndex: "userName",
          ellipsis: true,
          align: "center",
          width: "100px",
        },
        {
          title: "客服姓名",
          dataIndex: "servcieUserName",
          ellipsis: true,
          align: "center",
          width: "100px",
        },
        {
          title: "进件时间",
          dataIndex: "createTime",
          ellipsis: true,
          align: "center",
          width: "170px",
        },
        // {
        //   title: "申请金额",
        //   dataIndex: "yxEdu",
        //   align: "right",
        //   width: "120px",
        //   scopedSlots: { customRender: "yxEdu" },
        // },
        {
          title: "进件状态",
          dataIndex: "jinjianStatus",
          ellipsis: true,
          align: "center",
          width: "180px",
          scopedSlots: { customRender: "jinjianStatus" },
        },
        {
          title: "合同签署",
          dataIndex: "hetongQianshu",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "hetongQianshu" },
        },

        {
          title: "服务合同",
          dataIndex: "serviceContractSign",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "serviceContractSign" },
        },

        {
          title: "GPS安装",
          dataIndex: "isGps",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "isGps" },
        },

        {
          title: "备用钥匙",
          dataIndex: "beiyongKey",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "beiyongKey" },
        },

        {
          title: "抵押下单",
          dataIndex: "diyaSign",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "diyaSign" },
        },

        {
          title: "抵押寄出",
          dataIndex: "diyaSendOut",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "diyaSendOut" },
        },
        {
          title: "车辆保单",
          dataIndex: "carInsurancePolicy",
          align: "center",
          width: "90px",
          scopedSlots: { customRender: "carInsurancePolicy" },
        },

        {
          title: "放款时间",
          dataIndex: "fkTime",
          align: "right",
          width: "120px",
        },
        {
          title: "机构产品",
          dataIndex: "orgType",
          ellipsis: true,
          align: "center",
          width: "300px",
          scopedSlots: { customRender: "orgType" },
        },
        // {
        //   title: "进件类型",
        //   dataIndex: "jinjianType",
        //   scopedSlots: { customRender: "jinjianType" },
        //   align: "center",
        //   width: "100px",
        // },

        {
          title: "还款方式",
          dataIndex: "backType",
          scopedSlots: { customRender: "backType" },
          align: "center",
          width: "120px",
        },
        {
          title: "分期时间（月）",
          dataIndex: "fenqiTime",
          align: "right",
          width: "120px",
        },
        {
          title: "月供（元）",
          dataIndex: "monthAmount",
          align: "right",
          width: "100px",
        },
        {
          title: "抵押时间(月)",
          dataIndex: "diyaTime",
          ellipsis: true,
          align: "left",
          width: "100px",
        },
        {
          title: "签单时间",
          dataIndex: "qiandanTime",
          align: "center",
          width: "170px",
        },
        {
          title: "服务费用",
          dataIndex: "serviceAmount",
          align: "right",
          width: "100px",
          scopedSlots: { customRender: "serviceAmount" },
        },
        {
          title: "费用备注",
          dataIndex: "serviceAmountRemark",
          ellipsis: true,
          align: "left",
          width: "120px",
        },

        {
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "90px",
          fixed: "right",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    this.getList();
    this.getDicts("product_type").then((response) => {
      this.jinjianTypeOptions = response.data;
    });
    this.getDicts("back_type").then((response) => {
      this.backTypeOptions = response.data;
    });
    this.getDicts("org_type_options").then((response) => {
      this.orgTypeOptions = response.data;
    });
    this.getDicts("jinjian_status").then((response) => {
      this.jinjianStatusOptions = response.data;
    });
  },
  methods: {
    // 进件状态字典翻译
    jinjianStatusFormat(row) {
      if (row.jinjianStatus) {
        return this.selectDictLabel(
          this.jinjianStatusOptions,
          row.jinjianStatus
        );
      } else {
        return "";
      }
    },
    // 进件只读
    handleRead(record, ids) {
      this.showReadOnlyModal = true;
      this.$nextTick(() =>
        this.$refs.bizJinjianInfoMyQianyuueReadOnlyForm.handleUpdate(
          record,
          ids
        )
      );
    },

    // 签约
    handleUpdateQianYue(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizJinjianInfoEditForm.handleUpdate(record, ids)
      );
    },
    // 请款
    handleUpdateQingKuan(record, ids) {
      this.showQkModal = true;
      this.$nextTick(() =>
        this.$refs.bizJinjianInfoQkForm.handleUpdate(record, ids)
      );
    },

    // 放款
    handleUpdateFangK(record, ids) {
      this.showFkModal = true;
      this.$nextTick(() =>
        this.$refs.bizJinjianInfoFkForm.handleUpdate(record, ids)
      );
    },

    // 回款
    handleUpdateHuiK(record, ids) {
      this.showHkModal = true;
      this.$nextTick(() =>
        this.$refs.bizJinjianInfoHkForm.handleUpdate(record, ids)
      );
    },
    /** 获取产品信息 */
    handleGetProductInfo(value) {
      listBizProductInfo({ orgType: value, pageSize: 50 }).then((res) => {
        this.productList = res.data.list;
      });
    },
    /** 查询客户进件列表 */
    getList() {
      this.loading = true;
      listBizMyListQianyue(
        this.addDateRange(this.queryParam, this.dateRange)
      ).then((response) => {
        this.bizJinjianInfoList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 进件类型字典翻译
    jinjianTypeFormat(row) {
      if (row.jinjianType) {
        return this.selectDictLabel(this.jinjianTypeOptions, row.jinjianType);
      } else {
        return "";
      }
    },
    // 还款方式字典翻译
    backTypeFormat(row) {
      if (row.backType) {
        return this.selectDictLabel(this.backTypeOptions, row.backType);
      } else {
        return "";
      }
    },
    // 还款方式字典翻译
    orgTypeFormat(orgType) {
      if (orgType) {
        return this.selectDictLabel(this.orgTypeOptions, orgType);
      } else {
        return "";
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 刷新按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        status: "1",
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizJinjianInfoAddForm.handleAdd());
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizJinjianInfoEditForm.handleUpdate(record, ids)
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this;
      const bizJinjianInfoIds = row.id || this.ids;
      this.$confirm({
        title: "确认删除所选中数据?",
        onOk() {
          return delBizJinjianInfo(bizJinjianInfoIds).then(() => {
            that.onSelectChange([], []);
            that.getList();
            that.$message.success("删除成功", 3);
          });
        },
        onCancel() {},
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizJinjianInfo(that.queryParam).then((response) => {
            that.download(response.msg);
            that.$message.success("导出成功", 3);
          });
        },
        onCancel() {},
      });
    },
  },
};
</script>
